package ycl.base.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import ycl.base.entity.Area;
import ycl.base.req.AreaReq;
import ycl.base.res.AreaRes;
import ycl.base.service.AreaService;
import ycl.common.result.Result;
import ycl.common.base.controller.BaseRegionController;
import ycl.common.models.base.A;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 地区设置 前端控制器
 * </p>
 *
 * @author ycl
 * @since 2022-06-22 20:06:25
 */
@RestController
@RequestMapping("/area")
@Api(tags = "地区")
@ApiSupport(order = 4)
public class AreaController
		extends BaseRegionController<Area, AreaReq, AreaRes> {

	@Resource
	private AreaService areaService;

	@Override
	public Result<Area> getByCode(String code) {
		Area area = areaService.getByCode(code, Area.class);
		return Result.success(area);
	}

	@Override
	public Result<List<Area>> getByParentCode(String code) {
		List<Area> list = areaService.getByParentCode(code, Area.class);
		return Result.success(list);
	}

	@Override
	public Result<Page<AreaRes>> pageList(HttpServletRequest request, Area area) {
		return Result.success(areaService.pageList(request, area, AreaRes.class));
	}

	@Override
	public <E extends AreaReq> Result<A> save(HttpServletRequest request, @RequestBody @Valid E e) {
		areaService.save(request, e, Area.class);
		return Result.success();
	}

	@Override
	public <E extends AreaReq> Result<A> update(HttpServletRequest request, @RequestBody @Valid E e) {
		areaService.update(request, e, Area.class);
		return Result.success();
	}
}

